package com.carlos.company.config;

import com.carlos.company.controller.MyErrorController;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.ErrorProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.web.servlet.error.DefaultErrorAttributes;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.WebRequest;

/**
 * @author 李健成
 * @date 2021/10/19
 */

@Data
@Configuration
public class ErrorConfig {

    @Autowired
    private ServerProperties serverProperties;

    @Bean
    public MyErrorController myErrorController(ErrorAttributes errorAttributes) {
        return new MyErrorController(errorAttributes, serverProperties.getError());
    }

    @Bean
    public ErrorProperties errorProperties() {
        return new ErrorProperties();
    }

}
